﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class update_table_AppTopic : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainDataFormDict_MainProductTopic_ProductTopicId",
                table: "MainDataFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataModelDict_MainProductTopic_ProductTopicId",
                table: "MainDataModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataTableDict_MainProductTopic_ProductTopicId",
                table: "MainDataTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataViewContainerDict_MainProductTopic_ProductTopicId",
                table: "MainDataViewContainerDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainEventModelDict_MainProductTopic_ProductTopicId",
                table: "MainEventModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainOpenApiDict_MainProductTopic_TopicDictId",
                table: "MainOpenApiDict");

            migrationBuilder.DropTable(
                name: "EChartOptionConfig");

            migrationBuilder.DropTable(
                name: "EChartConfig");

            migrationBuilder.DropTable(
                name: "MainProductTopic");

            migrationBuilder.CreateTable(
                name: "MainAppTopic",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicCode = table.Column<string>(type: "text", nullable: false),
                    TopicName = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    OpenIddictApplicationId = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    ProductNamespaceId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainAppTopic", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainAppTopic_MainAppTopic_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainAppTopic",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_MainAppTopic_MainProductNamespace_ProductNamespaceId",
                        column: x => x.ProductNamespaceId,
                        principalTable: "MainProductNamespace",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_MainAppTopic_OpenIddictApplications_OpenIddictApplicationId",
                        column: x => x.OpenIddictApplicationId,
                        principalTable: "OpenIddictApplications",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainAppTopic_OpenIddictApplicationId",
                table: "MainAppTopic",
                column: "OpenIddictApplicationId");

            migrationBuilder.CreateIndex(
                name: "IX_MainAppTopic_ParentId",
                table: "MainAppTopic",
                column: "ParentId");

            migrationBuilder.CreateIndex(
                name: "IX_MainAppTopic_ProductNamespaceId",
                table: "MainAppTopic",
                column: "ProductNamespaceId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataFormDict_MainAppTopic_ProductTopicId",
                table: "MainDataFormDict",
                column: "ProductTopicId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataModelDict_MainAppTopic_ProductTopicId",
                table: "MainDataModelDict",
                column: "ProductTopicId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataTableDict_MainAppTopic_ProductTopicId",
                table: "MainDataTableDict",
                column: "ProductTopicId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataViewContainerDict_MainAppTopic_ProductTopicId",
                table: "MainDataViewContainerDict",
                column: "ProductTopicId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainEventModelDict_MainAppTopic_ProductTopicId",
                table: "MainEventModelDict",
                column: "ProductTopicId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainOpenApiDict_MainAppTopic_TopicDictId",
                table: "MainOpenApiDict",
                column: "TopicDictId",
                principalTable: "MainAppTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainDataFormDict_MainAppTopic_ProductTopicId",
                table: "MainDataFormDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataModelDict_MainAppTopic_ProductTopicId",
                table: "MainDataModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataTableDict_MainAppTopic_ProductTopicId",
                table: "MainDataTableDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainDataViewContainerDict_MainAppTopic_ProductTopicId",
                table: "MainDataViewContainerDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainEventModelDict_MainAppTopic_ProductTopicId",
                table: "MainEventModelDict");

            migrationBuilder.DropForeignKey(
                name: "FK_MainOpenApiDict_MainAppTopic_TopicDictId",
                table: "MainOpenApiDict");

            migrationBuilder.DropTable(
                name: "MainAppTopic");

            migrationBuilder.CreateTable(
                name: "MainProductTopic",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    NamespaceDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    TopicCode = table.Column<string>(type: "text", nullable: false),
                    TopicName = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProductTopic", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainProductTopic_MainProductNamespace_NamespaceDictId",
                        column: x => x.NamespaceDictId,
                        principalTable: "MainProductNamespace",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_MainProductTopic_MainProductTopic_ParentId",
                        column: x => x.ParentId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "EChartConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    Contdesc = table.Column<string>(type: "text", nullable: true),
                    EChartCodg = table.Column<string>(type: "text", nullable: false),
                    EChartName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EChartConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EChartConfig_MainProductTopic_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainProductTopic",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "EChartOptionConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    EChartConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EChartOptionConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EChartOptionConfig_EChartConfig_EChartConfigId",
                        column: x => x.EChartConfigId,
                        principalTable: "EChartConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_EChartConfig_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_EChartOptionConfig_EChartConfigId",
                table: "EChartOptionConfig",
                column: "EChartConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainProductTopic_NamespaceDictId",
                table: "MainProductTopic",
                column: "NamespaceDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainProductTopic_ParentId",
                table: "MainProductTopic",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataFormDict_MainProductTopic_ProductTopicId",
                table: "MainDataFormDict",
                column: "ProductTopicId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataModelDict_MainProductTopic_ProductTopicId",
                table: "MainDataModelDict",
                column: "ProductTopicId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataTableDict_MainProductTopic_ProductTopicId",
                table: "MainDataTableDict",
                column: "ProductTopicId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainDataViewContainerDict_MainProductTopic_ProductTopicId",
                table: "MainDataViewContainerDict",
                column: "ProductTopicId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainEventModelDict_MainProductTopic_ProductTopicId",
                table: "MainEventModelDict",
                column: "ProductTopicId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainOpenApiDict_MainProductTopic_TopicDictId",
                table: "MainOpenApiDict",
                column: "TopicDictId",
                principalTable: "MainProductTopic",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
